"""
@author: wangxutao
@project: ZetCore
@file: middle_ware.py
@time: 2019/9/3 10:30
@desc:用于处理中间件的一些相关逻辑
"""
from django.utils.deprecation import MiddlewareMixin


class DisableCSRFCheck(MiddlewareMixin):

    # def __init__(self, get_response):
    #     self.get_response = get_response
    #     from apps.common.libs.white_list_handler import IPWhiteListHandler
    #
    #     IPWhiteListHandler.write_to_env_path()


    """
    关闭csrf校验
    """

    def process_request(self, request):
        setattr(request, '_dont_enforce_csrf_checks', True)


class GlobalRequestMiddleware(MiddlewareMixin):
    """
    获取全局request
    """
    __instance = None

    def process_request(self, request):
        GlobalRequestMiddleware.__instance = request

    @classmethod
    def get_request(cls):
        return cls.__instance
